﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.business;
using XinGuanERP.Services.business.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.business
{
    [DynamicApiController]
    public class ProductCategoryController
    {
        private readonly IProductCategoryService _productCategoryService;
        public ProductCategoryController(IProductCategoryService productCategoryService)
        {
            _productCategoryService = productCategoryService;
        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil AddProductCategory(ProductCategoryVo productCategoryVo) =>
            ResultUtil.ok(_productCategoryService.AddProductCategory(productCategoryVo));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil UpdateProductCategory(ProductCategoryVo productCategoryVo) =>
            ResultUtil.ok(_productCategoryService.UpdateProductCategory(productCategoryVo));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil DeleteProductCategory(string id) =>
            ResultUtil.ok(_productCategoryService.DeleteProductCategory(id));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetProductCategoryTreeWithPage(int page, int pageSize) =>
            ResultUtil.ok(_productCategoryService.GetProductCategoryTreeWithPage(page, pageSize));
        /// <summary>
        /// 获取父级分类树：2级树
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetParentProductCategoryTree() =>
            ResultUtil.ok(_productCategoryService.GetParentProductCategoryTree());
    }
}
